<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // let time = new Date();
        // console.log(time);
        fn();

        function fn() {
            let time = new Date();
            console.log(time);

            // 第二部:通过日期变量分别获取系统时间的年月日时分秒
            // 获取年:
            let year = time.getFullYear();

            // console.log(year);
            // 获取月份: 月份从0开始的,一般值后面加1
            let month = time.getMonth() + 1;

            // 获取日期:
            let dt = time.getDate();

            // 获取时:
            let h = time.getHours();

            // 获取分钟:
            let m = time.getMinutes();

            // 获取秒:
            let s = time.getSeconds();
            console.log(`${year}-0${month}-0${dt}  ${h}:${m}:${s}`);
            setTimeout(fn, 1000)
        }
    </script>
</body>

</html>